home *** CD-ROM | disk | FTP | other *** search
/ Amiga Aktuell / Amiga Aktuell.iso / libs / dummylib.c < prev    next >
C/C++ Source or Header  |  1996-09-05  |  5KB  |  233 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: dummylib.c,v 1.3 1996/08/13 15:35:11 digulla Exp $
  4.     $Log: dummylib.c,v $
  5.     Revision 1.3  1996/08/13 15:35:11  digulla
  6.     Replaced __AROS_LA by __AROS_LHA
  7.  
  8.     Revision 1.2  1996/08/01 17:41:28  digulla
  9.     Added standard header for all files
  10.  
  11.     Desc:
  12.     Lang:
  13. */
  14. #include <exec/types.h>
  15. #include <exec/resident.h>
  16. #include <clib/exec_protos.h>
  17. #include <aros/libcall.h>
  18. #ifdef __GNUC__
  19.     #include "dummylib_gcc.h"
  20. #endif
  21. #include "initstruct.h"
  22.  
  23. struct inittable;
  24. extern const char name[];
  25. extern const char version[];
  26. extern const APTR inittabl[4];
  27. extern void *const functable[];
  28. extern const struct inittable datatable;
  29. extern struct dummybase *dummy_init();
  30. extern struct dummybase *dummy_open();
  31. extern BPTR dummy_close();
  32. extern BPTR dummy_expunge();
  33. extern int dummy_null();
  34. extern ULONG dummy_add();
  35. extern ULONG dummy_asl();
  36. extern const char end;
  37.  
  38. int entry(void)
  39. {
  40.     /* If the library was executed by accident return error code. */
  41.     return -1;
  42. }
  43.  
  44. const struct Resident resident=
  45. {
  46.     RTC_MATCHWORD,
  47.     (struct Resident *)&resident,
  48.     (APTR)&end,
  49.     RTF_AUTOINIT,
  50.     1,
  51.     NT_LIBRARY,
  52.     0,
  53.     (char *)name,
  54.     (char *)&version[6],
  55.     (ULONG *)inittabl
  56. };
  57.  
  58. const char name[]="dummy.library";
  59.  
  60. const char version[]="$VER: dummy 1.0 (28.3.96)\n\015";
  61.  
  62. const APTR inittabl[4]=
  63. {
  64.     (APTR)sizeof(struct dummybase),
  65.     (APTR)functable,
  66.     (APTR)&datatable,
  67.     &dummy_init
  68. };
  69.  
  70. void *const functable[]=
  71. {
  72.     &dummy_open,
  73.     &dummy_close,
  74.     &dummy_expunge,
  75.     &dummy_null,
  76.     &dummy_add,
  77.     &dummy_asl,
  78.     (void *)-1
  79. };
  80.  
  81. struct inittable
  82. {
  83.     S_CPYO(1,1,B);
  84.     S_CPYO(2,1,L);
  85.     S_CPYO(3,1,B);
  86.     S_CPYO(4,1,W);
  87.     S_CPYO(5,1,W);
  88.     S_CPYO(6,1,L);
  89.     S_END (end);
  90. };
  91.  
  92. #define O(n) offsetof(struct dummybase,n)
  93.  
  94. const struct inittable datatable=
  95. {
  96.     { { I_CPYO(1,B,O(library.lib_Node.ln_Type)), { NT_LIBRARY } } },
  97.     { { I_CPYO(1,L,O(library.lib_Node.ln_Name)), { (LONG)name } } },
  98.     { { I_CPYO(1,B,O(library.lib_Flags       )), { LIBF_SUMUSED|LIBF_CHANGED } } },
  99.     { { I_CPYO(1,W,O(library.lib_Version     )), { 1 } } },
  100.     { { I_CPYO(1,W,O(library.lib_Revision    )), { 0 } } },
  101.     { { I_CPYO(1,L,O(library.lib_IdString    )), { (LONG)&version[6] } } },
  102.     I_END ()
  103. };
  104.  
  105. #undef O
  106.  
  107. __AROS_LH2(struct dummybase *, init,
  108.  __AROS_LHA(struct dummybase *, dummybase, D0),
  109.  __AROS_LHA(BPTR,               segList,   A0),
  110.        struct ExecBase *, SysBase, 0, dummy)
  111. {
  112.     __AROS_FUNC_INIT
  113.     /* This function is single-threaded by exec by calling Forbid. */
  114.  
  115.     /* Store arguments */
  116.     dummybase->sysbase=SysBase;
  117.     dummybase->seglist=segList;
  118.  
  119.     /* You would return NULL here if the init failed. */
  120.     return dummybase;
  121.     __AROS_FUNC_EXIT
  122. }
  123.  
  124. /* Use This from now on */
  125. #ifdef SysBase
  126. #undef SysBase
  127. #endif
  128. #define SysBase dummybase->sysbase
  129.  
  130. __AROS_LH1(struct dummybase *, open,
  131.  __AROS_LHA(ULONG, version, D0),
  132.        struct dummybase *, dummybase, 1, dummy)
  133. {
  134.     __AROS_FUNC_INIT
  135.     /*
  136.     This function is single-threaded by exec by calling Forbid.
  137.     If you break the Forbid() another task may enter this function
  138.     at the same time. Take care.
  139.     */
  140.  
  141.     /* Keep compiler happy */
  142.     version=0;
  143.  
  144.     /* I have one more opener. */
  145.     dummybase->library.lib_OpenCnt++;
  146.     dummybase->library.lib_Flags&=~LIBF_DELEXP;
  147.  
  148.     /* You would return NULL if the open failed. */
  149.     return dummybase;
  150.     __AROS_FUNC_EXIT
  151. }
  152.  
  153. __AROS_LH0(BPTR, close, struct dummybase *, dummybase, 2, dummy)
  154. {
  155.     __AROS_FUNC_INIT
  156.     /*
  157.     This function is single-threaded by exec by calling Forbid.
  158.     If you break the Forbid() another task may enter this function
  159.     at the same time. Take care.
  160.     */
  161.  
  162.     /* I have one fewer opener. */
  163.     if(!--dummybase->library.lib_OpenCnt)
  164.     {
  165.     /* Delayed expunge pending? */
  166.     if(dummybase->library.lib_Flags&LIBF_DELEXP)
  167.         /* Then expunge the library */
  168.         return expunge();
  169.     }
  170.     return 0;
  171.     __AROS_FUNC_EXIT
  172. }
  173.  
  174. __AROS_LH0(BPTR, expunge, struct dummybase *, dummybase, 3, dummy)
  175. {
  176.     __AROS_FUNC_INIT
  177.  
  178.     BPTR ret;
  179.     /*
  180.     This function is single-threaded by exec by calling Forbid.
  181.     Never break the Forbid() or strange things might happen.
  182.     */
  183.  
  184.     /* Test for openers. */
  185.     if(dummybase->library.lib_OpenCnt)
  186.     {
  187.     /* Set the delayed expunge flag and return. */
  188.     dummybase->library.lib_Flags|=LIBF_DELEXP;
  189.     return 0;
  190.     }
  191.  
  192.     /* Get rid of the library. Remove it from the list. */
  193.     Remove(&dummybase->library.lib_Node);
  194.  
  195.     /* Get returncode here - FreeMem() will destroy the field. */
  196.     ret=dummybase->seglist;
  197.  
  198.     /* Free the memory. */
  199.     FreeMem((char *)dummybase-dummybase->library.lib_NegSize,
  200.         dummybase->library.lib_NegSize+dummybase->library.lib_PosSize);
  201.  
  202.     return ret;
  203.     __AROS_FUNC_EXIT
  204. }
  205. __AROS_LH0I(int, null, struct dummybase *, dummybase, 4, dummy)
  206. {
  207.     __AROS_FUNC_INIT
  208.     return 0;
  209.     __AROS_FUNC_EXIT
  210. }
  211.  
  212. __AROS_LH2I(ULONG, add,
  213.     __AROS_LHA(ULONG,a,D0),
  214.     __AROS_LHA(ULONG,b,D1),
  215.     struct dummybase *,dummybase,5,dummy)
  216. {
  217.     __AROS_FUNC_INIT
  218.     return a+b;
  219.     __AROS_FUNC_EXIT
  220. }
  221.  
  222. __AROS_LH2I(ULONG, asl,
  223.     __AROS_LHA(ULONG,a,D0),
  224.     __AROS_LHA(ULONG,b,D1),
  225.     struct dummybase *,dummybase,6,dummy)
  226. {
  227.     __AROS_FUNC_INIT
  228.     return a<<b;
  229.     __AROS_FUNC_EXIT
  230. }
  231.  
  232. const char end=0;
  233.